package cn.tedu.micro.demo.test;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

public class StreamMap {
    public static void main(String[] args) {
        List<Integer> originNumber=new ArrayList<>();
        originNumber.add(1);
        originNumber.add(2);
        originNumber.add(3);
        //想将 1 2 3 映射成新的集合 1 4 9
       /* List<Integer> newNumber=new ArrayList<>();
        for (Integer number : originNumber) {
            //对数字做平方计算
            Integer result=new Double(Math.pow(number,2)).intValue();
            newNumber.add(result);
        }*/
        List<Integer> newNumber = originNumber.stream().map(number -> {
            //映射算法 平方
            Integer result = new Double(Math.pow(number, 2)).intValue();
            return result;
        }).collect(Collectors.toList());
        System.out.println(newNumber);
    }
}
